home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / H-I / HypertalkTools.cpt / Menus For HyperCard™ / card_3302.txt < prev    next >
Text File  |  1989-02-26  |  4KB  |  93 lines

  1. -- card: 3302 from stack: in
  2. -- bmap block id: 4796
  3. -- flags: 0000
  4. -- background id: 2721
  5. -- name: NewMenu
  6.  
  7.  
  8. -- part 1 (button)
  9. -- low flags: 00
  10. -- high flags: 0001
  11. -- rect: left=228 top=304 right=331 bottom=262
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 1
  15. -- font id: 0
  16. -- text size: 12
  17. -- style flags: 0
  18. -- line height: 16
  19. -- part name: 
  20.  
  21.  
  22. -- part contents for background part 20
  23. ----- text -----
  24. 3
  25.  
  26. -- part contents for background part 1
  27. ----- text -----
  28. XFCN
  29.  
  30. -- part contents for background part 22
  31. ----- text -----
  32. NewMenu("Title","Item 1","Item 2",...,"Item n")
  33.  
  34. -- part contents for background part 13
  35. ----- text -----
  36. NewMenu is an XFCN (external function) that allows you to add your own menus to a HyperCard stack.  You may have up to eight menus with up to 15 items per menu.  
  37.  
  38. The number the NewMenu function returns is a reference number to the menu you just installed.  You MUST have this number to delete or make changes to the menu later on!  
  39.  
  40. When you change userLevels, or select paint tools, or do anything to cause HyperCard to change the menu bar--your new menu will be erased from the menu bar.  It is NOT gone from memory, just from the menu bar.  To have it replaced automatically do the "on idle" routine shown below.  This will make sure your menu is showing whenever you are in browse mode (on idle is not called when you're in button, field, or paint tools mode).
  41.  
  42. Add an item like "(-" to insert a divider line between menu options.  You may also end items with a slash letter (as is "An item/I") to add command keys.
  43.  
  44. All this would generally be done in a stack's script as follows:
  45.  
  46. on openStack  --  display new menus
  47.   global menu1, menu2  --  keep the "handles" to the menus in these globals
  48.   put NewMenu("Beep","Once","Twice","(-","Boing/9") into menu1
  49.   if menu1 is 0 then answer("Unable to make menu 'BEEP'") with "Drat"
  50.   put NewMenu("Visual","Effect 1") into menu2
  51.   if menu2 is 0 then answer("Unable to make menu 'Visual'") with "Drat"
  52. end openStack
  53.  
  54. on closeStack  --  delete the menus we've created using the globals saved in openStack
  55.   global menu1, menu2
  56.   put DeleteMenu(menu1) into menu1  --  clearing global for safety
  57.   put DeleteMenu(menu2) into menu2
  58. end closeStack
  59.  
  60. on idle  --  call ShowMenu every so often just in case our menus vanished
  61.   global menu1, menu2, lastTick
  62.   if (the ticks-lastTick)>120 then  --  gives better performance than on every iteration
  63.     put the ticks into lastTick
  64.     ShowMenu(menu1)
  65.     ShowMenu(menu2)
  66.   end if
  67.   pass idle
  68. end idle
  69.  
  70. on doMenu which  --  get our menu items from doMenu before HyperCard does...
  71.   global menu1, menu2  -- for CheckMenu and EnableMenu below
  72.   if which is "Once" then
  73.     beep 1
  74.     get CheckMenu(menu1,1,true)
  75.   else if which is "Twice" then
  76.     beep 1
  77.     wait 4
  78.     beep 1
  79.     get CheckMenu(menu1,2,true)
  80.   else if which is "Boing" then
  81.     play "Boing"
  82.     get CheckMenu(menu1,4,true)
  83.   else if which is "Effect 1" then
  84.     push card
  85.     visual effect dissolve to black
  86.     pop card
  87.     get EnableMenu(menu2,1,false)
  88.     else pass doMenu  --  Remember to pass on menu commands you don't trap!
  89. end doMenu
  90.  
  91. Notice that if you want the menu to appear for all cards in the stack, you would place the NewMenu function in the stack's script and install it "on openStack" and remove it "on closeStack".  If you wanted a menu to appear only for a certain background, the commands would be in that background's script and done "on openBackground" and "on closeBackground".  And the commands to make a menu to appear only on a certain card would be done in that card's script "on openCard"/"on closeCard".
  92.  
  93.